/** @jsxImportSource @emotion/react */
import * as React from "react";
import {Button, Text, TextArea, useToast} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {itemA水质检} from "./WaterQuality";
import {itemA下结论} from "./Conclusion";
import {config设备概况, } from "./viewRes";
import {config热载体况} from "./CarrierCondition";

export const VsProjects默认=[
    {name:'在用有机热载体检验报告',ha:'Conclusion', do:true},
    //pdf: ?（附页）
];

export const tail注解 = <Text css={{"@media print": {fontSize: '0.75rem'}}}>
    注：a适用有机热载体最高工作温度低于其未使用时初馏点的条件下使用。<br/>
    <Text css={{display: 'block',textIndent:'2rem',"@media print": {fontSize:'inherit',textIndent:'1.5rem'}}}>
    b适用有机热载体最高工作温度高于其未使用时初馏点的条件下使用。</Text>
</Text>;

export const EntranceSetup =
    React.forwardRef((
        {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
    ) => {
        const atPrint = useMedia('print');
        const toast = useToast();
        const doCheckNames = React.useCallback((verId: string) => {
            const result = assertNamesUnique([{value: rep?.tzFields},
                {value: config设备概况, type:'esnt'}, {value: config热载体况, type:'esnt'},
                {value:[...itemA下结论, ...itemA水质检, ]},
                {value:['Projects', ]}
            ]);
            toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
        }, [rep,toast]);
        const {storage, setStorage} =React.useContext(EditStorageContext) as any;
        const getInpFilter = React.useCallback((par: any) => {
            const {_tblFixed, } =par||{};
            return {_tblFixed, };
        }, []);
        const {inp, setInp} = useItemInputControl({ref});
        if (atPrint) return null;
        else return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={'初始化本报告，默认值配置等'}>
                {process.env.REACT_APP_TEST==='true' && <><div>
                    <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                    <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                    <Text variant="h5">设置待测试表格的各列宽度：</Text>
                    <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                        JSON.parse(e.currentTarget.value??'[]');
                        setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
                </div></>
                }
                <hr/>
            </InspectRecordLayout>
        );
});
